﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _180FrameWork.CustControls
{
    public partial class CustComboBox : ComboBox,ICustControl
    {
        private bool _IsBind = false;
        public bool IsBind { get { return this._IsBind; } protected set { this._IsBind = value; } }

        private string _PropertName = "";
        public string PropertName { get { return this._PropertName; } set { this._PropertName = value; } }

        //private string _QueryName = "";
        //public string QueryName { get { return this._QueryName; } set { this._QueryName = value; } }

        public CustComboBox()
        {
            InitializeComponent();
        }
        public void SetValue(object strValue)
        {
            if (this.DataSource != null)
            {
                //foreach(var item in this.bs.List)
                //{
                //    var t = item.GetType();
                //}
                //this.bs.Position = this.bs.Find(this.ValueMember, strValue);
                this.SelectedValue = strValue;
            }
        }

        public object GetValue()
        {
            return this.SelectedValue;
        }

        public void Binding(object DataSource, string DataMember)
        {
            this.DataBindings.Add("SelectedValue", DataSource, DataMember);
            IsBind = true;
            //if (this.SelectedItem == null && bs.Count > 0)
            //{
            //    this.SelectedIndex = 0;
            //}
        }

        public void Clean()
        {

        }

        public void GetFocus()
        {
            this.Focus();
        }

        //new public object DataSource
        //{
        //    get
        //    {
        //        return this.bs.DataSource;
        //    }
        //    set
        //    {
        //        this.bs.DataSource = value;
        //        base.DataSource = this.bs.DataSource;
        //    }
        //}

        private void Control_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SendKeys.Send("{TAB}");
            }
        }
       
    }
}
